package model.generator;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

import model.Teacher;
import model.container.CourseContainer;
import model.container.OfferedCourseContainer;
import model.container.TeacherContainer;
import model.generator.enums.FirstName;
import model.generator.enums.LastName;

public class TeacherGenerator {

	private static Random random = new Random();

	// METHODS

	/**
	 * A static Teacher generator method that generates Teachers with random
	 * properties.
	 * 
	 * @param count
	 *            The amount of teachers that should be generated.
	 * @return A Collection of Teachers with random properties.
	 */
	public static ArrayList<Teacher> generateTeachers(int count)
			throws Exception {

		ArrayList<Teacher> teachers = new ArrayList<Teacher>();

		for (int i = 0; i < count; i++) {
			FirstName[] names = FirstName.values();
			LastName[] lastNames = LastName.values();
			String name = names[random.nextInt(names.length)].getValue() +" " +  lastNames[random.nextInt(lastNames.length)].getValue() ;
			Teacher teacher = new Teacher("" + i,
					name,
					random.nextInt(10) * 100);

			teachers.add(teacher);
		}

		return teachers;
	}

	/**
	 * Initialize the Teacher reference fields
	 */
	public static void finishTeacherInitialisation() {
		OfferedCourseContainer offeredCourseContainer = OfferedCourseContainer.getInstance();
		List<Teacher> teachers = TeacherContainer.getInstance()
				.getTeachers();
		for (int i = 0; i < teachers.size(); i++) {
			teachers.get(i).setCoursePreferences(
					CourseGenerator.getRandomCourses());
			teachers.get(i)
					.setOfferedCourses(
							offeredCourseContainer.getOfferedCoursesForTeacher(teachers
											.get(i)));
		}

	}

	public static List<Teacher> getRandomTeachers() {
		TeacherContainer teacherContainer = TeacherContainer.getInstance();
		int toIndex = random.nextInt(teacherContainer.getTeacherCount());
		int fromIndex = toIndex > 0 ? random.nextInt(toIndex) : 0;
		return teacherContainer.getTeachers().subList(fromIndex, toIndex);
	}
}
